<template>
    <div>
        <h3>房号添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房型</td>
                    <td>
                        <select v-model="querinfo.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.list">{{ item.HouseTypeName }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">房间号码</td>
                    <td>
                        <input type="text" v-model="querinfo.HouseNoNumber">
                    </td>
                </tr>

                <tr>
                    <td align="right">房间描述</td>
                    <td>
                        <textarea cols="30" rows="5" v-model="querinfo.Desc"></textarea>
                    </td>
                </tr>

                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" v-model="querinfo.State" :value="1">上架
                        <input type="radio" v-model="querinfo.State" :value="0">下架
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="添加" @click="ok" class="btn btn-primary">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();
let querinfo:any=reactive({
    "HouseTypeId":"" ,
  "HouseNoNumber": "",
  "Desc": "",
  "State": "",
})
onMounted(()=>{
    getHouseType();
})

let data: any = reactive({
    list: [],
})
const ok=()=>{
    if(querinfo.HouseTypeId==""){
        alert('房型不能为空');
        return;
    }
    if(querinfo.HouseNoNumber==""){
        alert('房间号码不能为空');
        return;
    }
    if(querinfo.Desc==""){
        alert('房号描述不能为空');
        return;
    }
   
    axios({
        method:"post",
        url:"/api/House/AddHouseNo",
        data:querinfo
    })
    .then(res=>{
        if(res.data==-1){
            alert('房号名称重复')
        }
        else if(res.data>0){
            alert('添加成功')
            router.push('/housenoshow')
        }
        else{
            alert('添加失败')
        }
    })
}



const getHouseType = () => {
    axios({
        method: "get",
        url: "/api/House/ShowHouseType",
        params: {
            pageSize:100
        }
    })
        .then(res => {
            data.list = res.data.list
        })
}




</script>

<style scoped>

</style>